package logic

import (
	"Wei-Xin/models"
	"context"

	"Wei-Xin/weixinrpc/internal/svc"
	"Wei-Xin/weixinrpc/weixinrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MomentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMomentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MomentAddLogic {
	return &MomentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 发布朋友圈
func (l *MomentAddLogic) MomentAdd(in *weixinrpc.MomentAddRequest) (*weixinrpc.MomentAddResponse, error) {
	// todo: add your logic here and delete this line

	moment := models.Moment{
		Content: in.Content,
		UserId:  int(in.UserId),
	}

	models.DB.Debug().Create(&moment)

	return &weixinrpc.MomentAddResponse{
		MomentId: int64(moment.ID),
	}, nil
}
